import { Component, EventEmitter, Output } from '@angular/core';
import { Router } from '@angular/router';
import { Location } from '@angular/common';

import { PageTitle } from "./page-title"

@Component({
  selector: 'page-header',
  templateUrl: "./page-header.component.html",
  styleUrls: ["./page-header.component.css"]
})
export class PageHeaderComponent {
  @Output() toggleSidenav = new EventEmitter<void>()

  constructor(private pageTitle: PageTitle,
              private router: Router,
              private location: Location) { }

  goBack(): any {
    if (!this.pageTitle.back || this.pageTitle.back == "back")
      return this.location.back()

    return this.router.navigate([ this.pageTitle.back ])
  }

  getBack(): string { return this.pageTitle.back }

  getTitle(): string { return this.pageTitle.title }
}
